package jmine.tec.persist.schema.cascade;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.schema.simple.SimpleEntity;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;

@Entity
@Alias("CASC")
@Table(name = "CASCADE")
@Documentation("TABELA")
@SequenceGenerator(name = "SEQ_CASC", sequenceName = "SEQ_CASC")
public class CascadeEntityValue extends PersistableBusinessObject {

    private Long id;

    private Map<Integer, SimpleEntity> simpleMap;

    public CascadeEntityValue(Long id) {
        this.id = id;
    }

    public CascadeEntityValue() {

    }

    @Id
    @GeneratedValue(generator = "SEQ_CASC")
    @Column(name = "COD_CASC", nullable = false)
    @Documentation("CODIGO")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param simple the simple to set
     */
    public void setSimpleMap(Map<Integer, SimpleEntity> simpleMap) {
        this.simpleMap = simpleMap;
    }

    /**
     * @return the simple
     */
    @OneToMany
    @Cascade({ CascadeType.ALL })
    public Map<Integer, SimpleEntity> getSimpleMap() {
        return this.simpleMap;
    }

    public void put(Integer key, SimpleEntity value) {
        if (this.simpleMap == null) {
            this.simpleMap = new LinkedHashMap<Integer, SimpleEntity>();
        }
        this.simpleMap.put(key, value);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

}
